#ifndef _PAGE_H_
#define _PAGE_H_

/**
 * @file page.h/cpp
 * @version 1.0.0
 * @author how_fly@yahoo.com ( how_fly@yahoo.com )
 * @date 2008-08-24 created
*/

#include "url.h"
#include "keyword.h"
#include <list>
#include <map>
using namespace std;

#define TITILE_LEN 128
#define HOST_LEN 128
#define HREF_TIP_LEN 128
#define HREF_NAME_LEN 128



enum eHREF_TYPE
{
	eHREF_UNKNOWN = 0,
	eHREF_HTML = 1,
	eHREF_ASP = 3,
	eHREF_JSP = 4,
	eHREF_PHP = 5,
	eHREF_IMG = 6, //jpg, ico, png, bmp, ....
	eHREF_ZIPRAR = 7, //zip, rar, tar, gz....
	eHREF_MOVIE = 8, //wmf, wmv, asf, avi, ...
	eHREF_FLASH = 9 ,//flv, swf, ....
	eHREF_DOC = 10 , //doc, exl, 
	eHREF_JS = 11, //.js
	eHREF_CSS = 12, //.css
	eHREF_MUSIC = 13, //.mp3, mp2, mp4, wav, mid
	eHREF_XML = 14
};

struct href_t
{
	url_t url;
	eHREF_TYPE type; //is html to show, or zip, jpg, ico to download
	char tip[HREF_TIP_LEN];
	char name[HREF_NAME_LEN];
};
void init_href(href_t* href);
void del_href(href_t* href);


enum eBRACKETCONTENT_TYPE
{
	eMETA = 1,
};
struct bracketcontent_t
{
	eBRACKETCONTENT_TYPE bracketcontent_type;
	int len;
	char* p;
};
void init_bracketcontent(bracketcontent_t* bracketcontent);
void del_bracketcontent(bracketcontent_t* bracketcontent);
void add_to_bracketcontent(char* p, int len, bracketcontent_t* bracketcontent);

struct body_t
{
	int len;
	char* p;
};
void init_body(body_t* body);
void del_body(body_t* body);
/*
struct keyword_t
{
	string word;
	int count;
};
*/

enum eCHARSET_TYPE
{
	eCHARSET_UNKNOWN = 0,
	eCHARSET_UTF8 = 1,
	eCHARSET_GB2312 = 2,
	eCHARSET_GBK = 3,
};
struct page_t
{
	eCHARSET_TYPE charset_type;
	url_t url; //self url
	
	char title[TITILE_LEN];
	
	char host[HOST_LEN];// 'www.aaa.com/'
	
	list<bracketcontent_t*> bracketcontents;
	list<href_t*> hrefs;
	body_t body;
	//map<string, int> keywords;
	keyword_t* keyword;
	time_t check_time;
	
	int ref_count;
	pthread_mutex_t locker_ref_count;
};

//void init_page(page_t* page, url_t* url);
void increase_page(page_t* page, int count);
int release_page(page_t* page, bool del);

int add_href_to_page(char* p, int len, page_t* page);
int add_bracketcontent_to_page(char* p, int len, page_t* page);
#endif

